<template>
	<view class="container">
		<view class="poupbox">
			<view class="label">选择研学项目</view>
			<view class="itemall">
				<view
					v-for="(t, idx) in yanxuelist"
					:key="idx"
					:class="{ checkimg: t.id == currentId, imgbox: true }"
					@click="setCurrentId('currentId', t.id)"
				>
					<image class="img" :src="t.coverImage" mode="aspectFill"></image>
					<view :class="{ checkimg: t.id == currentId, text: true }">{{ t.goodsName }}</view>
				</view>
				<view class="imgbox" style="height: 0"></view>
				<view class="imgbox" style="height: 0"></view>
				<view class="imgbox" style="height: 0"></view>
				<!-- <view class="imgbox">
          <image class="img"></image>
          <view class="text">国美研学</view>
        </view>
        <view class="imgbox">
          <image class="img"></image>
          <view class="text">京都研学1</view>
        </view>
        <view class="imgbox">
          <image class="img"></image>
          <view class="text">徽州研学</view>
        </view> -->
			</view>
			<view class="label">选择研学时间</view>
			<view class="itemall" style="flex-wrap: wrap">
				<view
					v-for="(t, idx) in specList1"
					:class="{ timebox: true, timecheck: specId1 == t.id }"
					:key="idx"
					@click="setCurrentId('specId1', t.id)"
				>
					{{ t.specName + ':' + t.specValue }}
				</view>
			</view>
			<view class="label">目标招生人数</view>
			<view class="itemall" style="flex-wrap: wrap">
				<view
					v-for="(t, idx) in specList2"
					:class="{ peoplenum: true, timecheck: specId2 == t.id }"
					:key="idx"
					@click="setCurrentId('specId2', t.id)"
				>
					{{ t.specValue }}
				</view>
				<view class="peoplenum" v-for="t in 4" :key="t" style="height: 0" />
			</view>
			<view class="faqi" @click="toFaqiFunc" v-if="!isxcwl">立即发起我的研学</view>
			<view class="faqi" @click="towlFunc" v-if="isxcwl">生成物料链接</view>
			<view class="wllianjie" v-if="isxcwl">
				{{ textUrl }}
				<text v-if="!textUrl" style="color: #cacaca">复制百度网盘链接-前往百度网盘app打开即可</text>
				<view :class="{ btn: true, ishigh: textUrl != '' }" @click="copyLink">复制链接</view>
			</view>
			<view style="height: 100rpx"></view>
		</view>
	</view>
</template>
<script>
import yanxueApi from '@/api/yanxue/yanxue'
export default {
	data() {
		return {
			yanxuelist: [],
			specList1: [],
			specList2: [],
			currentId: 0,
			specId1: 0,
			specId2: 0,
			isxcwl: false,
			textUrl: ''
		}
	},
	onLoad(options) {
		console.log(options, options.type == 'xcwl')
		if (options.type == 'xcwl') {
			this.isxcwl = true
			uni.setNavigationBarTitle({
				title: '宣传物料'
			})
		}
		this.getProjectListFunc()
	},
	methods: {
		copyLink() {
			if (!this.textUrl) {
				uni.showToast({
					title: '暂无物料链接',
					icon: 'none'
				})
			} else {
				uni.setClipboardData({
					data: this.textUrl,
					success: function () {
						uni.showToast({
							title: '复制成功',
							icon: 'none'
						})
					},
					fail: function (err) {
						console.error('复制失败', err)
					}
				})
			}
		},
		towlFunc() {
			this.textUrl = ''
			this.yanxuelist.map(x => {
				if (x.id == this.currentId) {
					this.textUrl = x.dbLink
				}
			})
			if (!this.textUrl) {
				uni.showToast({
					title: '暂无物料链接',
					icon: 'none'
				})
			}
		},
		toFaqiFunc() {
			let obj = {
				dateId: this.specId1,
				goodsId: this.currentId,
				numberId: this.specId2
			}
			const app = this
			uni.showModal({
				title: '温馨提示',
				content: '是否发起研学',
				cancelText: '取消',
				confirmText: '确定',
				success: res => {
					if (res.confirm) {
						yanxueApi.releaseProject(obj).then(res => {
							uni.showToast({
								title: '发起成功',
								icon: 'none'
							})
							setTimeout(() => {
								app.$navTo('pages/yanxue/index')
							}, 1200)
						})
					}
				}
			})
		},
		setCurrentId(type, id) {
			this[type] = id
			if (type == 'currentId') {
				this.getProjectSpecFunc(id)
			}
		},
		getProjectListFunc() {
			yanxueApi.getProjectList().then(res => {
				this.yanxuelist = res.result
				this.getProjectSpecFunc(res.result[0].id)
			})
		},
		getProjectSpecFunc(id) {
			console.log(id)
			this.currentId = id
			yanxueApi
				.getProjectSpec({
					id
				})
				.then(res => {
					console.log(res)
					this.specList1 = res.result.specList1
					this.specList2 = res.result.specList2
					this.specId1 = res.result.specList1[0].id
					this.specId2 = res.result.specList2[0].id
				})
		}
	}
}
</script>
<style lang="scss" scoped>
.container {
	width: 750rpx;
	height: 100vh;
	position: relative;
	z-index: 99;
	background: #757575;

	.poupbox {
		top: 3vh;
		z-index: 99;
		position: absolute;
		width: 750rpx;
		height: 97vh;
		background: #ffffff;
		border-radius: 20rpx 20rpx 0rpx 0rpx;
		padding: 42rpx 48rpx;

		.label {
			height: 30rpx;
			font-family: HarmonyOS Sans SC;
			font-weight: 400;
			font-size: 32rpx;
			color: #000000;
			margin-bottom: 42rpx;
		}

		.itemall {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 60rpx;
		}

		.imgbox {
			width: 160rpx;
			height: 234rpx;
			background: #e3e3e3;
			border-radius: 20rpx;
			//   border: 4px solid #f95513;
			margin-right: 5rpx;
			box-sizing: border-box;

			.img {
				width: 150rpx;
				height: 150rpx;
				margin: 4rpx;
				// background: pink;
				border-radius: 20rpx;
			}

			.text {
				height: 40rpx;
				width: 150rpx;
				display: -webkit-box;
				/* 必须设置为 -webkit-box 或者其他 flexbox 布局 */
				-webkit-box-orient: vertical;
				/* 设置或继承对象的子元素排列方式 */
				-webkit-line-clamp: 1;
				/* 设置显示的行数 */
				overflow: hidden;
				/* 隐藏溢出的内容 */
				text-overflow: ellipsis;
				/* 显示省略号 */
				text-align: center;
				font-family: HarmonyOS Sans SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #262626;
				margin: 8rpx auto 0 auto;
			}
		}

		.checkimg {
			background: #f95513;
			color: #fff !important;
		}

		.timebox {
			width: 700rpx;
			height: 66rpx;
			text-align: center;
			line-height: 66rpx;
			background: #e3e3e3;
			border-radius: 33rpx;
			font-family: HarmonyOS Sans SC;
			font-weight: 400;
			font-size: 28rpx;
			margin-bottom: 26rpx;
			color: #262626;
		}

		.peoplenum {
			width: 144rpx;
			height: 66rpx;
			text-align: center;
			line-height: 66rpx;
			border-radius: 33rpx;
			background: #e3e3e3;
			border-radius: 33rpx;
			font-family: HarmonyOS Sans SC;
			font-weight: 400;
			font-size: 28rpx;
			margin-bottom: 26rpx;
			color: #262626;
		}

		.timecheck {
			background: #f95513;
			color: #ffffff;
		}

		.faqi {
			width: 644rpx;
			height: 84rpx;
			line-height: 84rpx;
			text-align: center;
			background: #f95513;
			border-radius: 42rpx;
			font-family: HarmonyOS Sans SC;
			font-weight: 500;
			font-size: 30rpx;
			color: #ffffff;
			padding-bottom: 30rpx;
		}

		.wllianjie {
			width: 636rpx;
			height: 232rpx;
			background: #f6f6f6;
			border-radius: 20rpx;
			margin-top: 40rpx;
			position: relative;
			font-family: HarmonyOS Sans SC;
			font-weight: 400;
			font-size: 28rpx;
			color: #262626;
			padding: 22rpx 30rpx;

			.btn {
				width: 168rpx;
				height: 92rpx;
				background: #dddddd;
				border-radius: 20rpx;
				font-family: HarmonyOS Sans SC;
				font-weight: bold;
				font-size: 30rpx;
				color: #f6f6f6;
				line-height: 92rpx;
				text-align: center;
				position: absolute;
				bottom: 10rpx;
				left: 230rpx;
			}

			.ishigh {
				background: #f95513;
				color: #fff;
			}
		}
	}
}
</style>
